using System;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.Windows.Forms;

namespace EIM_Accounting
{
    /// <summary>
    /// 合同 合同管理 合同费用列表
    /// </summary>
    public partial class CP010104 : Form
    {
        BLL.CP010104 cp010104 = new BLL.CP010104();

        public CP010104()
        {
            InitializeComponent();
            setDataGridwiewHeader();
        }

        private void setDataGridwiewHeader()
        {
            DataGridViewColumn dgvc = new DataGridViewTextBoxColumn();
            dgvc.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dgvc.DataPropertyName = "ID";
            dgvc.HeaderText = "ID";
            dgvc.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dataGridView1.Columns.Add(dgvc);
            dataGridView1.Columns[0].Visible = false;

            dgvc = new DataGridViewTextBoxColumn();
            dgvc.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dgvc.Width = 140;
            dgvc.HeaderText = "费用日期";
            dgvc.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dataGridView1.Columns.Add(dgvc);

            dgvc = new DataGridViewTextBoxColumn();
            dgvc.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
            dgvc.Width = 200;
            dgvc.HeaderText = "合约";
            dgvc.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dataGridView1.Columns.Add(dgvc);

            dgvc = new DataGridViewTextBoxColumn();
            dgvc.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dgvc.Width = 100;
            dgvc.HeaderText = "类别";
            dgvc.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dataGridView1.Columns.Add(dgvc);

            dgvc = new DataGridViewTextBoxColumn();
            dgvc.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
            dgvc.DefaultCellStyle.Font = new Font("华文新魏", 12F, FontStyle.Italic);
            dgvc.DefaultCellStyle.ForeColor = Color.DarkGreen;
            dgvc.Width = 80;
            dgvc.HeaderText = "金额";
            dgvc.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dataGridView1.Columns.Add(dgvc);

            dgvc = new DataGridViewTextBoxColumn();
            dgvc.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
            dgvc.Width = 450;
            dgvc.HeaderText = "备注";
            dgvc.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dgvc.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
            dataGridView1.Columns.Add(dgvc);

            foreach (DataGridViewColumn cdd in dataGridView1.Columns)
            {
                cdd.SortMode = DataGridViewColumnSortMode.NotSortable;
            }
            dataGridView1.EnableHeadersVisualStyles = false;
            dataGridView1.Columns[0].HeaderCell.Style.ForeColor = Color.Yellow;
            dataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.SteelBlue;
            dataGridView1.ColumnHeadersDefaultCellStyle.ForeColor = SystemColors.Info;
            dataGridView1.ColumnHeadersDefaultCellStyle.Font = new Font("楷体_GB2312", 14F, FontStyle.Regular);
            dataGridView1.ColumnHeadersHeight = 60;

            //dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            dataGridView1.AllowUserToResizeColumns = false;
            dataGridView1.AllowUserToResizeRows = false;

            dataGridView1.RowHeadersVisible = false;
            dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;

            dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = System.Drawing.Color.Lavender;//System.Drawing.Color.FromArgb(60, 250, 240, 230);
            dataGridView1.AllowUserToOrderColumns = false;

            dataGridView1.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
            dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
        }

        private void CP010104_Load(object sender, System.EventArgs e)
        {
            setDataGridView();
        }

        private void setDataGridView()
        {
            dataGridView1.Rows.Clear();

            DataSet ds = cp010104.GetDataList();
            int iCount = 0;
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                string id = dr["ID"].ToString();
                string signComp = dr["SignComp"].ToString();

                string remark = dr["Remark"].ToString();

                dataGridView1.Rows.Add(new string[] { id, DateTime.ParseExact(dr["ActionDate"].ToString(), "yyyyMMdd", CultureInfo.InvariantCulture).ToString("yyyy年MM月dd日"), signComp, dr["ActionType"].ToString(), decimal.Parse(dr["ActionFee"].ToString()).ToString("#,###.00"), remark });
                if (decimal.Parse(dr["ActionFee"].ToString()) > 0)
                {
                    dataGridView1.Rows[iCount].Cells[4].Style.ForeColor = Color.Red;
                }
                else
                {
                    dataGridView1.Rows[iCount].Cells[4].Style.ForeColor = Color.DarkBlue;
                }

                iCount++;
            }
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            CP010103 cp010103 = new CP010103();
            cp010103.ShowDialog();

            setDataGridView();
        }
    }
}